package com.xiyi_design.printer_manage.pub;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class AccessInterceptorConfig implements WebMvcConfigurer {
    @Value("${spring.profiles.active}")
    private String mActive;
    @Resource
    AccessInterceptor accessInterceptor;

    /**
     * 将拦截器加入项目
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        if (mActive.equals("prod")){
            registry.addInterceptor(accessInterceptor).addPathPatterns("/**").excludePathPatterns("/test/**", "/js/**", "/images/**");
        }
        else {
            registry.addInterceptor(accessInterceptor).addPathPatterns("/**").excludePathPatterns("/test/**", "/log/**", "/js/**", "/images/**");
        }
    }
}
